//
//  UIButton+Extension.m
//  UEP
//
//  Created by Bcc on 15/5/15.
//  Copyright (c) 2015年 eReach. All rights reserved.
//

#import "UIButton+Extension.h"

@implementation UIButton (Extension)
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state
{
    [self setBackgroundImage:[UIButton imageWithColor:backgroundColor] forState:state];
}

+ (UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}
-(void)setDefaultStyle
{
    self.layer.cornerRadius = CORNERRADIUS_BUTTON_LITTLE;
    self.layer.masksToBounds = YES;
    self.titleLabel.font = DEFAULT_FONT;
    [self setBackgroundColor:Blue_Color forState:UIControlStateNormal];
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self setBackgroundColor:[UIColor colorWithRed:0.373 green:0.478 blue:0.588 alpha:1.000] forState:UIControlStateHighlighted];
    self.adjustsImageWhenHighlighted = NO;
}

-(void)setReverseStyle
{
    self.layer.borderWidth = 0.5;
    self.layer.borderColor = Blue_Color.CGColor;
    self.layer.cornerRadius = CORNERRADIUS_BUTTON_LITTLE;
    self.layer.masksToBounds = YES;
    self.titleLabel.font = DEFAULT_FONT;
    [self setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self setTitleColor:Blue_Color forState:UIControlStateNormal];
    [self setBackgroundColor:[UIColor colorWithRed:0.373 green:0.478 blue:0.588 alpha:1.000] forState:UIControlStateHighlighted];
    self.adjustsImageWhenHighlighted = NO;
}

-(void)setMiniFontSizeStyle
{
    self.layer.cornerRadius = CORNERRADIUS_BUTTON_LITTLE;
    self.layer.masksToBounds = YES;
    self.titleLabel.font = DEFAULT_FONT_13;
    [self setBackgroundColor:Blue_Color forState:UIControlStateNormal];
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self setBackgroundColor:[UIColor colorWithRed:0.373 green:0.478 blue:0.588 alpha:1.000] forState:UIControlStateHighlighted];
    self.adjustsImageWhenHighlighted = NO;
}
@end
